import { useCallback } from 'react';
import useBasisCash from './useBasisCash';
import { Bank } from '../basis-cash';
import useHandleTransactionReceipt from './useHandleTransactionReceipt';
import { parseUnits } from 'ethers/lib/utils';
import { VoteInfo } from '../basis-cash/types';

const useVoted = (vote: VoteInfo) => {
  const basisCash = useBasisCash();
  const handleTransactionReceipt = useHandleTransactionReceipt();

  const handleStake = useCallback(
    (name: string) => {
      const nameBn = parseUnits(name, 0);
      handleTransactionReceipt(
        basisCash.voted(vote.contract, nameBn),
        `Vote ${'vSHARE'} to ${vote.contract}`,
      );
    },
    [vote, basisCash],
  );
  return { onVoted: handleStake };
};

export default useVoted;
